home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Archive / QuickTime / QuickTime VR / Make QTVR Panorama / CPrefsWindow.cp < prev    next >
Encoding:
Text File  |  2000-09-28  |  5.3 KB  |  244 lines  |  [TEXT/CWIE]

  1. /*
  2.     A window that provides the user interface for editing preferences.
  3.     
  4.     Created 29 Jan 1996 by EGH
  5.     
  6.     Copyright © 1996, Apple Computer, Inc. All rights reserved.
  7. */
  8.  
  9. #include <QuickTimeComponents.h>
  10.  
  11. #include <String_Utils.h>
  12.  
  13. #include "CKeyFilters.h"
  14. #include "CUtils.h"
  15.  
  16. #include "CPrefsWindow.h"
  17.  
  18. // =========
  19. // constants
  20.  
  21. const PaneIDT Button_Okay = 'okay';
  22. const PaneIDT Button_Cancel = 'canc';
  23. const PaneIDT Button_Compression = 'comp';
  24. const PaneIDT Caption_Compression = 'coms';
  25. const PaneIDT Edit_Width = 'widt';
  26. const PaneIDT Edit_Height = 'heig';
  27. const PaneIDT Edit_TileSuffix = 'tile';
  28. const PaneIDT Edit_MovieSuffix = 'move';
  29. const PaneIDT Check_ReplaceFiles = 'dele';
  30. const PaneIDT Edit_Pan = 'pan ';
  31. const PaneIDT Edit_Tilt = 'tilt';
  32. const PaneIDT Edit_Zoom = 'zoom';
  33.  
  34. // =========
  35.  
  36.  
  37. //static
  38. CPrefsWindow *CPrefsWindow::CreatePrefsWindowWindowStream(
  39.     LStream    *inStream)
  40. {
  41.     return new CPrefsWindow(inStream);
  42. }
  43.  
  44. CPrefsWindow::CPrefsWindow(
  45.     LStream    *inStream) :
  46.     LDialogBox(inStream)
  47. {
  48.     mPrefsHdl = gApp->GetPreferences();
  49.     ThrowIfNil_(mPrefsHdl);
  50.     
  51.     mSpatialQuality = (*mPrefsHdl)->spatialQuality;
  52.     mDepth = (*mPrefsHdl)->depth;
  53.     mCodec = (*mPrefsHdl)->codec;
  54. }
  55.  
  56. CPrefsWindow::~CPrefsWindow()
  57. {
  58. }
  59.  
  60. void CPrefsWindow::FinishCreateSelf()
  61. {
  62.     LDialogBox::FinishCreateSelf();
  63.     AddAttachment(new LUndoer); // for the edits
  64.     
  65.     SetValueForPaneID(Edit_Width, (*mPrefsHdl)->width);
  66.     SetValueForPaneID(Edit_Height, (*mPrefsHdl)->height);
  67.     
  68.     LPane *pane = FindPaneByID(Edit_TileSuffix);
  69.     if (pane != nil)
  70.     {
  71.         pane->SetDescriptor((*mPrefsHdl)->tileSuffix);
  72.     }
  73.     pane = FindPaneByID(Edit_MovieSuffix);
  74.     if (pane != nil)
  75.     {
  76.         pane->SetDescriptor((*mPrefsHdl)->movieSuffix);
  77.     }
  78.     
  79.     Str255 valueStr;
  80.     LEditField *edit = (LEditField *)FindPaneByID(Edit_Pan);
  81.     if (edit != nil)
  82.     {
  83.         edit->SetKeyFilter(CKeyFilters::RealNumberFieldPositive);
  84.         FixedToStr((*mPrefsHdl)->pan, valueStr);
  85.         edit->SetDescriptor(valueStr);
  86.     }
  87.     edit = (LEditField *)FindPaneByID(Edit_Tilt);
  88.     if (edit != nil)
  89.     {
  90.         edit->SetKeyFilter(CKeyFilters::RealNumberField);
  91.         FixedToStr((*mPrefsHdl)->tilt, valueStr);
  92.         edit->SetDescriptor(valueStr);
  93.     }
  94.     edit = (LEditField *)FindPaneByID(Edit_Zoom);
  95.     if (edit != nil)
  96.     {
  97.         edit->SetKeyFilter(CKeyFilters::RealNumberFieldPositive);
  98.         FixedToStr((*mPrefsHdl)->zoom, valueStr);
  99.         edit->SetDescriptor(valueStr);
  100.     }
  101.     
  102.         // find and listen to the buttons
  103.     LButton *button;
  104.     button = (LButton *)FindPaneByID(Button_Okay);
  105.     ThrowIfNil_(button);
  106.     button->AddListener(this);
  107.     
  108.     button = (LButton *)FindPaneByID(Button_Cancel);
  109.     ThrowIfNil_(button);
  110.     button->AddListener(this);
  111.     
  112.     button = (LButton *)FindPaneByID(Button_Compression);
  113.     ThrowIfNil_(button);
  114.     button->AddListener(this);
  115.     
  116.     LStdCheckBox *check = (LStdCheckBox *)FindPaneByID(Check_ReplaceFiles);
  117.     ThrowIfNil_(check);
  118.     check->SetValue((*mPrefsHdl)->replaceFiles);
  119.     
  120.     SetCompressionText(FindPaneByID(Caption_Compression), mCodec, mSpatialQuality);
  121. }
  122.  
  123.  
  124. /* CPrefsWindow::ListenToMessage
  125.  
  126.     Listen in on what is happening in the user interface.
  127. */
  128. void CPrefsWindow::ListenToMessage(
  129.     MessageT inMessage,
  130.     void *ioParam)
  131. {
  132.     switch (inMessage)
  133.     {
  134.         case Button_Okay:
  135.         {
  136.             (*mPrefsHdl)->codec = mCodec;
  137.             (*mPrefsHdl)->depth = mDepth;
  138.             (*mPrefsHdl)->spatialQuality = mSpatialQuality;
  139.             
  140.             LPane *pane;
  141.             pane = FindPaneByID(Edit_TileSuffix);
  142.             if (pane != nil)
  143.                 pane->GetDescriptor((*mPrefsHdl)->tileSuffix);
  144.             pane = FindPaneByID(Edit_MovieSuffix);
  145.             if (pane != nil)
  146.                 pane->GetDescriptor((*mPrefsHdl)->movieSuffix);
  147.             
  148.             Str255 valueStr;
  149.             pane = FindPaneByID(Edit_Pan);
  150.             if (pane != nil)
  151.             {
  152.                 pane->GetDescriptor(valueStr);
  153.                 (*mPrefsHdl)->pan = StrToFixed(valueStr);
  154.             }
  155.             pane = FindPaneByID(Edit_Tilt);
  156.             if (pane != nil)
  157.             {
  158.                 pane->GetDescriptor(valueStr);
  159.                 (*mPrefsHdl)->tilt = StrToFixed(valueStr);
  160.             }
  161.             pane = FindPaneByID(Edit_Zoom);
  162.             if (pane != nil)
  163.             {
  164.                 pane->GetDescriptor(valueStr);
  165.                 (*mPrefsHdl)->zoom = StrToFixed(valueStr);
  166.             }
  167.             
  168.             (*mPrefsHdl)->width = GetValueForPaneID(Edit_Width);
  169.             (*mPrefsHdl)->height = GetValueForPaneID(Edit_Height);
  170.             
  171.             (*mPrefsHdl)->replaceFiles = GetValueForPaneID(Check_ReplaceFiles) != 0;
  172.             
  173.             // fall through
  174.         }
  175.         
  176.         case Button_Cancel:
  177.             delete this;
  178.             break;
  179.         
  180.         case Button_Compression:
  181.         {
  182.             ComponentInstance ci = 
  183.                 ::OpenDefaultComponent(StandardCompressionType, StandardCompressionSubType);
  184.             ThrowIfNil_(ci);
  185.             
  186.             try
  187.             {
  188.                 ComponentResult result;
  189.                 
  190.                 SCSpatialSettings ss;
  191.                 ss.codecType = mCodec;
  192.                 ss.spatialQuality = mSpatialQuality;
  193.                 ss.depth = mDepth;
  194.                 ss.codec = nil;
  195.                 result = ::SCSetInfo(ci, scSpatialSettingsType, &ss);
  196.                 ThrowIf_(result < 0);
  197.                 
  198.                 result = ::SCRequestImageSettings(ci);
  199.                 ThrowIf_(result < 0);
  200.                 
  201.                 if (result != scUserCancelled)
  202.                 {
  203.                     result = ::SCGetInfo(ci, scSpatialSettingsType, &ss);
  204.                     ThrowIf_(result < 0);
  205.                     mCodec = ss.codecType;
  206.                     mSpatialQuality = ss.spatialQuality;
  207.                     mDepth = ss.depth;
  208.                     
  209.                     SetCompressionText(FindPaneByID(Caption_Compression), mCodec, mSpatialQuality);
  210.                 }
  211.             }
  212.             catch (ExceptionCode inErr)
  213.             {
  214.                 ::CloseComponent(ci);
  215.                 ReportError(inErr, err_ErrorSettingCompression);
  216.             }
  217.             
  218.             ::CloseComponent(ci);
  219.             break;
  220.         }
  221.         
  222.         default:
  223.             
  224.             LDialogBox::ListenToMessage(inMessage, ioParam);
  225.     }
  226. }
  227.  
  228.  
  229. void CPrefsWindow::FindCommandStatus(
  230.     CommandT inCommand,
  231.     Boolean &outEnabled,
  232.     Boolean &outUsesMark,
  233.     Char16 &outMark,
  234.     Str255 outName)
  235. {
  236.     
  237. }
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.